"""
---------------------------------------------------------------------
- File: users.py
- Date: 2025/11/5
- Author: yangzhide
- Email: xxzjyzd@126.com
- Description: 系统用户相关的schema
---------------------------------------------------------------------
"""

from sqlmodel import Field, SQLModel

from app.schemas.enums import GenderEnum, UserStatusEnum
from app.schemas.sqlmode_base import IdTimeModel


class UserBase(SQLModel):
    """
    用户基础模型
    """

    user_no: str = Field(..., description="编号")
    user_name: str = Field(..., description="名称")
    nick_name: str | None = Field(None, description="昵称")
    user_gender: GenderEnum | None = Field(GenderEnum.MALE.value, description="性别: M-男, F-女")
    user_email: str | None = Field(None, description="邮箱")
    user_phone: str | None = Field(None, description="手机号")
    status: UserStatusEnum | None = Field(UserStatusEnum.ACTIVE.value, description="状态: Y-激活, N-禁用")


class UserCreate(UserBase):
    """
    用户创建模型
    """

    password: str = Field(..., description="密码")


class UserUpdate(UserBase):
    """
    用户更新模型
    """

    # 所有字段设置为可选
    user_no: str | None = Field(None, description="用户编号")
    user_name: str | None = Field(None, description="用户名称")


class UserRead(IdTimeModel, UserBase):
    """
    用户读取模型
    """

    pass


class RoleInfo(SQLModel):
    id: int | None = Field(None, description="角色ID")
    role_no: str | None = Field(None, description="角色编号")
    role_name: str | None = Field(None, description="角色名称")


class UserWithRoles(UserRead):
    """
    用户角色模型
    """

    roles: list[RoleInfo] = Field(description="角色")
